/** ###################################################################
**     Filename  : data.H
**     Project   : Motologger_v2
**     Processor : MC9S12XA256CFU
**     Compiler  : CodeWarrior HCS12X C Compiler
**     Date/Time : 12/7/2009, 7:46 PM
**     Contents  :
**         User source code
**
**     (c) Copyright UNIS, a.s. 1997-2008
**     UNIS, a.s.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

#ifndef __data_H
#define __data_H

/* MODULE data */

//data.h data formatting info for the Fonera

#include "Config.h"

//byte length of data types
#define time_bytes      2  //real time clock from microcontroller
#define GPS_bytes       100  //#bytes in a GPS string
#define vel_bytes       2   //velocity int
#define acc_bytes       6   //accelerometer int x,y,z
#define acc_x_bytes 2
#define acc_y_bytes     2
#define acc_z_bytes 2
#define brake_bytes 2 //braking 1=yes, 2=no
#define gear_bytes  2 //0=neutral
#define rpm_bytes       2
#define command_bytes 1

#define rpm_tag         'r'
#define time_tag        't'
#define GPS_tag         'g'
#define vel_tag         'v'
#define acc_tag         'a'
#define batt_tag        'b'
#define gear_tag        'e'
#define command_tag 'c' //for commands to fonera from 6812

void write_header(int file_fd, configFileType* cfg_file);
void convert_4to8(char *input, char* output, int input_size);
void convert_8to4(char *input, char* output, int input_size);
void read_write_serial_data(int file_fd, int console_int);

// struct
// data
// {
// int time_stamp;
// char type;//v=velocity, r=rpm, b=breaking, g=gps, x=acceleration x-directed,y=acceleration y-directed,z=acceleration z-directed,
// int data;
// char GPS[GPS_bytes];//inefficient but easy. probably not a problem if the struct is only around for a short time
// };

// struct
// data_string
// {
// char type;
// char time_stamp[time_bytes];
// char data[GPS_bytes];//null terminated string of data,GPS will be the longest data string
// };



typedef struct _accelData{
       char tag;
       char dummy;
       unsigned short time_stamp;
       short x;
       short y;
       short z;
}accelDataType;

typedef struct _velData{
       char tag;
       char dummy;
       unsigned short time_stamp;
       unsigned short velocity;
}velDataType;

typedef struct _rpmData{
       char tag;
       char dummy;
       unsigned short time_stamp;
       unsigned short RPM;
}rpmDataType;

typedef struct _gearData{
       char tag;
       char dummy;
       unsigned short time_stamp;
       unsigned short gear;
}gearDataType;

typedef struct _battData{
       char tag;
       char dummy;
       unsigned short time_stamp;
       unsigned short batt;
}battDataType;

typedef struct _gpsData{
       char tag;
       char dummy;
       unsigned short time_stamp; //ignore this gps is self-timestamped
       unsigned char gpsData[GPS_bytes];
}gpsDataType;

typedef struct _timeData{
       unsigned char tag;
       unsigned char dummy;
       unsigned short time_stamp;
}timeDataType;


typedef struct _commandData{
       unsigned char tag;
       unsigned char dummy;
       unsigned short command;
       unsigned short param;
}commandDataType;


#endif
